﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Data;
using System.Globalization;
using System.Windows.Media.Imaging;


using System.ComponentModel;

namespace Mskold.IterationManager
{


   public  class ProgressViewModel: INotifyPropertyChanged
    {
       private List<ActionExec> actions;

        public List<ActionExec> Actions
        {
            get { return actions; }
            set { actions = value;
                    NotifyPropertyChanged("Actions");
            }
        }
        
        public ProgressViewModel()
        {
            actions = new List<ActionExec>();

        }

        public void  SetActions(List<IAction> lst)
        {

            foreach (IAction a in lst)
            {
                Actions.Add(new ActionExec() { theAction = a, Status = ActionExecStatus.Queued });
            }

        }

       public  Dictionary<string, object> sharedVariables;
               #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;


        public  void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion
    }

   public enum ActionExecStatus { Queued, Runing, Done, Failed }

    public class ActionExec :INotifyPropertyChanged
    {
    
    
        public IAction theAction;

        public string Title { get { return theAction.Title; } }
        public ActionExecStatus Status 
        {
            get {return _status;}
            set{ _status = value;  NotifyPropertyChanged("Status");}
        }
        public string Message
        {
            get { return _message; }
            set { _message = value; NotifyPropertyChanged("Message"); }
        }

        public string Log { get;set; }



        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;


        public void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion

        private ActionExecStatus _status;
        private string _message;
    }



    public class EnumToPicConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            switch ((ActionExecStatus)value)
            {
                case ActionExecStatus.Queued:
                    return null;    
                //return new BitmapImage(new Uri("running.bmp", UriKind.Relative));
                case ActionExecStatus.Runing:
                    return new BitmapImage(new Uri("pack://application:,,,/IterationManager;component/Resources/Running.png"));
                case ActionExecStatus.Done:
                    return new BitmapImage(new Uri("pack://application:,,,/IterationManager;component/Resources/Done.png"));
                case ActionExecStatus.Failed:
                    return new BitmapImage(new Uri("pack://application:,,,/IterationManager;component/Resources/Failed.png"));
                default:
                    break;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //You could convert back here
            return null;
        }
    }


}
